import Vue from 'vue'
import VueRouter from 'vue-router'
// import Film from '../views/Film'
// import Cinema from '../views/Cinema'
// import News from '../views/News'
// import User from '../views/User'
// import Nowplaying from '../views/Films/Nowplaying'
// import Comingsoon from '../views/Films/Comingsoon'
// import Login from '../views/Login'
// import { component } from 'vue/types/umd'
// import { component } from 'vue/types/umd'

Vue.use(VueRouter)

const routes = [{
        path: '/Film',
        component: () =>
            import ('../views/Film'),
        children: [{
                path: '/Film/Nowplaying',
                component: () =>
                    import ('../views/Films/Nowplaying')
            },
            {
                path: '/Film/Comingsoon',
                component: () =>
                    import ('../views/Films/Comingsoon')
            },

            {
                path: '',
                redirect: '/Film/Nowplaying'
            }
        ]
    },
    {
        path: '/Theater',
        component: () =>
            import ('../views/Theater'),
        children: [{
                path: '/Theater/hotshowing',
                component: () =>
                    import ('../views/Theater/hotshowing'),
            },
            {
                path: '/Theater/foreshow',
                component: () =>
                    import ('../views/Theater/foreshow'),
            },
            {
                path: '/Theater/sayfilm',
                component: () =>
                    import ('../views/Theater/sayfilm'),
            },
            {
                path: '/Theater/goodfilm',
                component: () =>
                    import ('../views/Theater/goodfilm'),
            },
            {
                path: '/Theater/hitshow',
                component: () =>
                    import ('../views/Theater/hitshow'),
            },
            {
                path: '/Theater/check',
                component: () =>
                    import ('../views/Theater/check'),
            },
            {
                path: '/Theater/circle',
                component: () =>
                    import ('../views/Theater/circle'),
            },
            {
                path: '/Theater/suspensefilm',
                component: () =>
                    import ('../views/Theater/suspensefilm'),
            },
            {
                path: '/Theater/sciencefilm',
                component: () =>
                    import ('../views/Theater/sciencefilm'),
            },
            {
                path: '/Theater/lovefilm',
                component: () =>
                    import ('../views/Theater/lovefilm'),
            },
            {
                path: '/Theater/strange',
                component: () =>
                    import ('../views/Theater/strange'),
            },
            {
                path: '',
                redirect: '/Theater/hotshowing'
            }
        ]
    },

    {
        path: '/Film/Classic',
        component: () =>
            import ('../views/Classic')
    },
    {
        path: '/Film/Cinema/Search',
        component: () =>
            import ('../components/Search')
    },
    {
        path: '/News',
        component: () =>
            import ('../views/News')
    },
    {
        path: '/City',
        component: () =>
            import ('../components/City')
    },
    {
        path: '/Film/Cinema',
        component: () =>
            import ('../views/Cinema')
    },
    {
        path: '/User',
        component: () =>
            import ('../views/User')
    },
    {
        path: '/Login',
        component: () =>
            import ('../views/Login')
    },
    {
        path: '/Detail/:filmId',
        component: () =>
            import ('../views/Detail')
    },
    {
        path: '/Moredetail/:filmId',
        component: () =>
            import ('../views/Moredetail')
    },
    {
        path: '*',
        redirect: '/Film'
    }
]

const router = new VueRouter({
    // mode: 'history',
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {
    const allow = ['/User']
    if (allow.includes(to.fullPath)) {
        if (!sessionStorage.getItem('code')) {
            next('/Login')
        } else {
            next()
        }
    } else {
        next()
    }
})

export default router